/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip.header;

import javax.sip.header.SubjectHeader;
import java.text.ParseException;

/**
 * The Subject header field provides a summary or indicates the nature of the
 * call, allowing call filtering without having to parse the session
 * description.  The session description does not have to use the same subject
 * indication as the invitation.
 * <p>
 * For Example:<br>
 * <code>Subject: Where is the Moscone?</code>
 *
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 */
public class SubjectHeaderImpl extends HeaderBase implements SubjectHeader {
    private String subject;

    private final static SubjectHeaderParser parser = new SubjectHeaderParser();

    public SubjectHeaderImpl() {
        super(SubjectHeader.NAME);
    }

    SubjectHeaderImpl(byte[] data, int start, int end) {
        super(SubjectHeader.NAME, data, start, end);
    }

    public Object clone() {
        final SubjectHeaderImpl header = new SubjectHeaderImpl();
        header.cloneBase(this);
        if (parsed) {
            header.subject = this.subject;
        }
        return header;
    }

    protected HeaderParser getParser() {
        return parser;
    }

    protected String getValueAsString() {
        return subject;
    }

    /**
     * Sets the subject value of the SubjectHeader to the supplied string
     * subject value.
     *
     * @param subject the new subject value of this header.
     * @throws java.text.ParseException which signals that an error has been reached
     *                                  unexpectedly while parsing the subject value.
     */

    public void setSubject(String subject) throws ParseException {
        parse();
        this.subject = subject;
        invalidateHeaderData();
    }

    /**
     * Gets the subject value of SubjectHeader.
     *
     * @return subject of SubjectHeader.
     */

    public String getSubject() {
        parse();
        return this.subject;
    }
}
/*
 * $Log$
 */